<template>
  <el-container class="bg_img1">
    <el-main class="bg_size1">
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        status-icon
        :rules="rules"
        class="demo-ruleForm"
      >
        <el-row>
          <el-col :span="9" :offset="7">
            <el-form-item label="时间名称：" prop="timename" class="item">
              <el-input v-model="ruleForm.timename" autocomplete="off" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="9" :offset="7">
            <el-form-item label="开始时间：" prop="begtime" class="item">
              <el-input v-model="ruleForm.begtime" autocomplete="off" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="9" :offset="7">
            <el-form-item label="结束时间：" prop="endtime" class="item">
              <el-input v-model="ruleForm.endtime" autocomplete="off" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="4" :offset="9">
            <el-form-item class="item">
              <el-button type="primary" @click="submitForm()">提交</el-button>
            </el-form-item>
          </el-col>

          <el-col :span="1">
            <el-form-item class="item">
              <el-button @click="resetForm()">清空</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-main>
  </el-container>
</template>

<script>
import { ElMessage } from "element-plus";
import axios from "axios";
import qs from "querystring";

export default {
  name: "UpdateShiJian",
  props: {
    current: {},
  },
  data() {
    return {
      ruleForm: {},
      rules: {
        timename: [
          {
            required: true,
            message: "请输入时间段名称",
            trigger: "blur",
          },
        ],
        begtime: [
          {
            required: true,
            message: "请输入开始时间",
            trigger: "blur",
          },
        ],
        endtime: [
          {
            required: true,
            message: "请输入结束时间",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      axios
        .post(
          "http://localhost:8080/library/updateSH",
          qs.stringify(this.ruleForm),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            },
          }
        )
        .then((res) => {
          // console.log(res.data.code);
          if (res.data.code == 1) {
            // console.log(this.list);
            window.alert("时间段信息修改成功！");
            this.list = res.data.data;
          } else {
            console.log("error");
          }
        });
    },
    resetForm() {
      (this.ruleForm.timename = ""),
      (this.ruleForm.begtime = ""),
      (this.ruleForm.endtime = "");
    },
  },
  mounted() {
    this.ruleForm = this.current;
  },
};
</script>

<style scoped>
</style>